<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>在指定时间内重复执行函数</title>
<script>
  function clock() {
      document.getElementById("clock").value = new Date().toLocaleTimeString();
  }
  var int = setInterval("clock()", 1);
</script>
</head>
<body>
  <label>
    当前时间
    <input type="text" id="clock" size="34" disabled>
  </label>
  <button onclick="int=clearInterval(int)">停止</button>
  <input type="button" onclick="int=setInterval('clock()', 1)" value="恢复">
</body>
</html>